<template>
    <div class="qrcode-wrapper">
        <centerHeader/>

        <div class="qrcode-wrap">
            <div class="top-wrap">
                <div class="title_box">
                    <span class="title-01">提现明细</span>
                    <i class="el-icon-arrow-down"></i>
                </div>
            </div>
            <div class="commission">
                <div class="clearfix com_box">
                    <span class="fl" style="font-size: 0.3rem">当前余额 <span class="com_color">{{user_info.user_money}}</span>元</span>
                    <div class="fr">
                        <el-button type="danger"  size="mini" round style="background-color:#bc9f5b;color:#ffffff;font-size:0.3rem;"  @click="open" >申请提现</el-button>
                    </div>

                </div>
                <transition name="slide-fade" class="tran_box">
                    <div class="hotKey-wrap" v-if="isDetail">
                        <div class="shop_detail">
                            <i class="el-icon-close shop_close" @click="close"></i>
                            <div class="add_clerk">
                                <el-form   label-width="80px" :model="formLabel">
                                    <el-form-item label="提现金额">
                                        <el-input  type="text" v-model="formLabel.tixian_money"  clearable></el-input>
                                    </el-form-item>
                                    <el-form-item label="姓名">
                                        <el-input  type="text" v-model="formLabel.tixian_username"  clearable></el-input>
                                    </el-form-item>
                                    <el-form-item label="开户行">
                                        <el-input  type="text" v-model="formLabel.tixian_bankname"  clearable></el-input>
                                    </el-form-item>
                                    <el-form-item label="银行卡号">
                                        <el-input  type="text" v-model="formLabel.tixian_banknumber"  clearable></el-input>
                                    </el-form-item>

                                </el-form>
                                <div class="submit-box">
                                    <button class="submit-btn"  @click="submit">提交申请</button>
                                </div>
                            </div>

                        </div>
                    </div>
                </transition>
                <div class="com_list">
                    <el-tabs  v-model="tixian_status" @tab-click="handleClick">
                        <el-tab-pane label="全部" name="-2">
                            <ul class="tab_ul" v-for="item in tixian_list" :key="item.tixian_id">
                                <li>
                                    <div class="tab_item_top clearfix">
                                        <div class="tab_item_time">{{item.create_time | formatDate}}</div>
                                        <div class="tab_item_type" v-if="item.tixian_status == -1">未通过</div>
                                        <div class="tab_item_type" v-else-if="item.tixian_status == 0">审核中</div>
                                        <div class="tab_item_type" v-else-if="item.tixian_status == 1">已审核</div>
                                    </div>
                                    <div class="tab_item_bottom">
                                        <div class="tab_item_top clearfix">申请提现{{item.tixian_money}}元</div>
                                        <div class="tab_item_timer">{{item.audit_time |formatDate}}</div>
                                    </div>
                                    <div class="tab_item_bottom" v-if="item.tixian_reason">
                                        <div class="tab_item_order">未通过原因:{{item.tixian_reason}}</div>
                                    </div>
                                </li>
                            </ul>
                        </el-tab-pane>
                        <el-tab-pane label="待审核" name="0">
                            <ul class="tab_ul" v-for="item in tixian_list" :key="item.tixian_id">
                                <li>
                                    <div class="tab_item_top clearfix">
                                        <div class="tab_item_time">{{item.create_time | formatDate}}</div>
                                        <div class="tab_item_type" v-if="item.tixian_status == -1">未通过</div>
                                        <div class="tab_item_type" v-else-if="item.tixian_status == 0">审核中</div>
                                        <div class="tab_item_type" v-else-if="item.tixian_status == 1">已审核</div>
                                    </div>
                                    <div class="tab_item_top clearfix">
                                        <div class="tab_item_order">申请提现{{item.tixian_money}}元</div>
                                        <div class="tab_item_timer">{{item.audit_time |formatDate}}</div>
                                    </div>
                                    <div class="tab_item_bottom" v-if="item.tixian_reason">
                                        <div class="tab_item_order">未通过原因:{{item.tixian_reason}}</div>
                                    </div>
                                </li>
                            </ul>
                        </el-tab-pane>
                        <el-tab-pane label="未通过" name="-1">
                            <ul class="tab_ul" v-for="item in tixian_list" :key="item.tixian_id">
                                <li>
                                    <div class="tab_item_top clearfix">
                                        <div class="tab_item_time">{{item.create_time | formatDate}}</div>
                                        <div class="tab_item_type" v-if="item.tixian_status == -1">未通过</div>
                                        <div class="tab_item_type" v-else-if="item.tixian_status == 0">审核中</div>
                                        <div class="tab_item_type" v-else-if="item.tixian_status == 1">已审核</div>
                                    </div>
                                    <div class="tab_item_top clearfix">
                                        <div class="tab_item_order">申请提现{{item.tixian_money}}元</div>
                                        <div class="tab_item_timer">{{item.audit_time |formatDate}}</div>
                                    </div>
                                    <div class="tab_item_bottom" v-if="item.tixian_reason">
                                        <div class="tab_item_order">未通过原因:{{item.tixian_reason}}</div>
                                    </div>
                                </li>
                            </ul>
                        </el-tab-pane>
                        <el-tab-pane label="已审核" name="1">
                            <ul class="tab_ul" v-for="item in tixian_list" :key="item.tixian_id">
                                <li>
                                    <div class="tab_item_top clearfix">
                                        <div class="tab_item_time">{{item.create_time | formatDate}}</div>
                                        <div class="tab_item_type" v-if="item.tixian_status == -1">未通过</div>
                                        <div class="tab_item_type" v-else-if="item.tixian_status == 0">审核中</div>
                                        <div class="tab_item_type" v-else-if="item.tixian_status == 1">已审核</div>
                                    </div>
                                    <div class="tab_item_top clearfix">
                                        <div class="tab_item_order">申请提现{{item.tixian_money}}元</div>
                                        <div class="tab_item_timer">{{item.audit_time |formatDate}}</div>
                                    </div>
                                    <div class="tab_item_bottom" v-if="item.tixian_reason">
                                        <div class="tab_item_order">未通过原因:{{item.tixian_reason}}</div>
                                    </div>
                                </li>
                            </ul>
                        </el-tab-pane>
                    </el-tabs>
                    <div class="submit-box">
                        <button class="submit-btn" @click="query_shop">下拉加载更多</button>
                    </div>
                </div>
            </div>
        </div>

        <centerFooter/>
    </div>
</template>

<script type="text/ecmascript-6">
    import centerHeader from "@/views/center/components/centerHeader";
    import centerFooter from "@/views/center/components/centerFooter";
    import constant from "@/utils/constant.js";
    import { formatTime } from "@/utils/index.js";
    import moment from 'moment'
    // 引用API文件
    import http from "@/utils/http.js";

    import QRCode from "qrcode";

    export default {
        name: "qrcode",
        data() {
            return {
                user_info: {
                    total_commission:0,
                    uid:""
                },
                isDetail:false,
                formLabel:{
                    tixian_money:"",
                    tixian_username:"",
                    tixian_bankname:"",
                    tixian_banknumber:""
                },
                p:0,
                tixian_list:[],
                tixian_status:"-2"
            };
        },
        filters:{
            formatDate(time){
                if(time == 0 || time == '' || time == null || time == undefined){
                    return ''
                }
                return moment(time*1000).format('YYYY-MM-DD')
            }
        },
        components: {
            centerHeader,
            centerFooter
        },
        methods: {
            userinfo() {
                http.get(this, {
                    url: "ucenter/user_info",
                    data: {
                        token: localStorage.getItem("user_token")
                    },
                    dataType: "json",
                    success: function(data) {
                        console.log("用户信息:", data);
                        if (data.status == 1) {
                            this.user_info = data.info;
                            this.p = 0
                            this.tixian_list = [];
                            this.query_list(this.tixian_status)
                        } else {
                        }
                    }
                });
            },
            close(){
                this.isDetail = false
            },
            open(){
                this.isDetail =true;
            },
            submit(){
                let user_type = localStorage.getItem('user_type')
                let tixian_from = 'store'
                if(user_type == 3){
                    tixian_from = 'store'
                }else{
                    tixian_from = 'pathform'
                }

                let user_money = parseFloat(this.user_info.user_money);

                if(user_money < parseFloat(this.formLabel.tixian_money)){
                    this.$message.error('申请提现的金额小于余额,不能提现')
                    return false;
                }

                if(parseFloat(this.formLabel.tixian_money) <= 0){
                    this.$message.error('申请提现的金额必须大于0')
                    return false;
                }

                http.post(this, {
                    url: "tixian/add",
                    data: {
                        token: localStorage.getItem("user_token"),
                        tixian_from:tixian_from,
                        ...this.formLabel
                    },
                    dataType: "json",
                    success: function(data) {
                        console.log("用户信息:", data);
                        if (data.status == 1) {
                            this.$message.success('申请提现完成')
                            this.isDetail = false
                            // this.p = 0
                            // this.tixian_list = [];
                            // this.query_list(this.tixian_status)
                            this.user_type = localStorage.getItem("user_type");
                            if (this.user_type == "store") {
                                this.storeinfo();
                            } else {
                                this.userinfo();
                            }
                        }
                    }
                });
            },
            query_list(tixian_status){
                this.p++;
                let params = {};
                let user_type = localStorage.getItem('user_type')
                if(user_type == 3){
                    params['uid'] = this.user_info.uid;
                    params['tixian_from'] = 'store';
                }
                else if(user_type == 'store'){
                    params['store_id'] = this.user_info.store_id;
                    params['tixian_from'] = 'pathform';
                }
                else{
                    params['uid'] = this.user_info.uid;
                    params['tixian_from'] = 'pathform';
                }
                http.get(this, {
                    url: "tixian/index",
                    data: {
                        pagesize: 5,
                        p: this.p,
                        token: localStorage.getItem("user_token"),
                        tixian_status:this.tixian_status != -2  ? this.tixian_status : "",
                        ...params
                    },
                    dataType: "json",
                    success: function(data) {
                        if (data.status == 1) {
                            let info = data.info;
                            if (this.p <= info.total_page) {
                                this.tixian_list = this.tixian_list.concat(info.list);
                            }
                        }
                    }
                });
            },
            handleClick(tab,event){
                this.p = 0
                this.tixian_list = [];
                this.query_list(this.tixian_status)
            },
            storeinfo() {
                http.get(this, {
                    url: "store/store_info",
                    data: {
                        token: localStorage.getItem("user_token")
                    },
                    dataType: "json",
                    success: function(data) {
                        console.log("门店信息:", data);
                        if (data.status == 1) {
                            this.user_info = data.info;
                            this.user_type = 'store';
                            this.user_info.user_money = data.info.store_money
                            // this.total_commission = data.info.total_commission;
                            // this.store_count = data.info.store_count;
                            localStorage.setItem("user_name", data.info.store_name);
                            //localStorage.setItem("user_head", data.info.headimgurl);
                            localStorage.setItem("user_type", 'store');
                            this.p = 0
                            this.tixian_list = [];
                            this.query_list(this.tixian_status)
                        } else {
                        }
                    }
                });
            },
            query_shop(){
                this.query_list()
            }
        },
        created() {
            // let user_type = localStorage.getItem("user_type");
            // if (user_type == "store") {
            //     this.storeinfo();
            // } else {
            //     this.userinfo();
            // }
        },
        activated(){
            let user_type = localStorage.getItem("user_type");
            if (user_type == "store") {
                this.storeinfo();
            } else {
                this.userinfo();
            }
        }
    };
</script>

<style scoped lang="scss">
    .qrcode-wrapper {
    }

    .top-wrap {
        $letHeight: 1.3rem;

        .title-txt {
            height: $letHeight;
            line-height: $letHeight;
            text-align: center;
            background-color: $c-white-light;

            span {
                color: $c-mainC;
                display: inline-block;
                line-height: $letHeight;
                vertical-align: middle;

                &.title-01 {
                    font-size: 0.38rem;
                }
            }
        }
    }

    .main-wrap {
        @extend .cmm-border;
    }

    .img-wrap {
        width: 5rem;
        height: 5rem;
        margin: 0.4rem auto;
        overflow: hidden;
        position: relative;
        padding: 0.22rem;

        .ad-img {
            @extend .cmm-translateXY;
            width: 100%;
        }
    }

    .qrcode-box {
        text-align: center;
        width: 100%;
        .qrcode-txt {
            width: 5.15rem;
            border-radius: 0.8rem;
            background-color: $c-danger;
            font-size: 0.52rem;
            color: $c-white-light;
            $letHeight: 0.6rem;
            height: $letHeight;
            line-height: $letHeight;
            text-align: center;
            margin: 0.48rem auto;
            display: inline-block;
            letter-spacing: 0.1rem;
            font-weight: bold;
        }
    }
    .title-txt-new{
        height:1rem;
        line-height:1rem;
        text-align: center;
        background-color: $c-white-light;
        font-size: 0.32rem;
    }
    .picker{
        padding:0 10px;
        border-top: 0.15rem solid #eeeeee;
        .el-date-editor.el-input, .el-date-editor.el-input__inner{
            width:2.2rem;
        }
        /deep/.el-input__inner{
            border: none;
        }
    }
    .shop_table_header{
        display: flex;
        line-height:1rem;
        padding:0 0.2rem;
        border-bottom:1px solid #eeeeee;
        &>div.th_one{
            flex:2
        }
        &>div.th_two{
            flex:1
        }
    }
    .shop_table_table{
        &>li{
            padding:0.25rem 0.2rem;
            display: flex;
            &>div.td_one{
                flex:2;
                &>div.td_item_one{
                    margin-bottom:0.2rem;
                }
                &>div.td_item_two{
                    &>span{
                        font-size: 0.08rem;
                    }

                }
            }
            &>div.td_two{
                flex:1;
                &>div.td_item_one{
                    margin-bottom:0.2rem;
                }
                &>div.td_item_two{
                    &>span{
                        font-size: 0.08rem;
                    }

                }
            }
        }
    }
    .title_box{
        height: 0.9rem;
        line-height:0.9rem;
        font-size: 0.36rem;
        text-align: center;
    }
    .commission{
        border-top: 0.15rem solid #eeeeee;
        .com_box{
            height: 1rem;
            line-height:1rem;
            padding:0 0.3rem;
            border-bottom:1px solid #eeeeee;
            &>span{
                line-height:1rem;
                display: flex;
                justify-content: center;
            }
        }
    }
    .fl{
        float: left;
    }
    .fr{
        float: right;
    }
    .com_title{
        height: 1rem;
        line-height:1rem;
        text-align: center;
        font-size: 0.36rem;
    }
    .com_ul{
        li{
            padding:0.25rem 0.3rem;
            border-bottom:1px solid #eeeeee;
            .com_top{
                line-height:0.5rem;
                margin-bottom:0.2rem;
            }
            .com_name{
                float: left;
            }
            .com_orderId{
                font-size: 0.2rem!important;
                float: left;
            }
            .com_price{
                font-size: 0.5rem;
                color:#ff4c4c;
                float: right;
            }
            .com_time{
                float: right;
            }
        }
    }
    .com_color{
        font-size: 0.45rem;
        color:#ff4c4c;
    }
    .com_list{
        font-size: 0.3rem;
        /deep/.el-tabs__nav-wrap{
            margin:0 0.25rem;
        }
        /deep/.el-tabs__nav{
            width:100%
        }
        /deep/.el-tabs__item{
            width:25%;
            text-align: center;
            height: 1rem;
            line-height:1rem;

        }
        /deep/.el-tabs__item.is-active{
            color: #ff4c4c;
            font-weight: 500;
        }
        /deep/.el-tabs__active-bar{
            background-color:#ff4c4c;
        }
        /deep/.el-tabs__nav-wrap::after{
            background-color: #ffffff;
        }
    }
    .tab_ul{
        li{
            padding:0.25rem;
            border-bottom:1px solid #eeeeee;
        }
        .tab_item_top{
            margin-bottom:0.28rem;
            .tab_item_time{
                float:left;
            }
            .tab_item_type{
                float:right;
            }
        }
    }
    .tab_item_bottom{
        display: flex;
        .tab_item_order{
            flex:1;
            text-align: left;
        }
        .tab_item_cash{
            flex: 1;
            text-align: center;
        }
        .tab_item_timer{
            flex: 1.2;
            text-align: right;
        }
    }
    .shop_close{
        position: absolute;
        right: 0.3rem;
        top:0.32rem;
        font-size: 0.32rem;
    }
    .add_clerk{
        padding-top:0.8rem;
        .title{
            font-size: 0.3rem;
            margin-bottom: 0.6rem;
            margin-left:0.2rem;
        }
        /deep/.el-input__inner{
            border-top:none;
            border-left:none;
            border-right:none;

        }
    }
    .shop_detail{
        position: relative;
        .shop_name{
            height:1rem;
            line-height:1rem;
            padding:0 0.4rem;

            font-size: 0.3rem;
        }
        .shop_other_box{
            border-bottom:0.013333rem solid #eeeeee;
            border-top:0.013333rem solid #eeeeee;
        }
        .shop_other{
            height: 0.8rem;
            line-height:0.8rem;
            padding:0 0.4rem;
        }
        .shop_price{
            height:4rem;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 0.32rem;
            color:#c09a5b;
        }
    }
    /deep/.el-form-item{
        margin-bottom:0.4rem;
    }
    /deep/.el-form-item__label{
        text-align: center;
    }
    .submit-box{
        padding: 0 0.2rem;
    }
    /deep/.el-tabs__item{
        font-size: 0.3rem;
    }
    /deep/.el-form-item__label{
        font-size: 0.3rem;
    }
    /deep/.el-input__inner{
        font-size: 0.3rem;
    }
</style>
